package cms.manage.template.value.impl;

import cms.bean.template.Forum;
import cms.manage.template.impl.FollowTemplateManage;
import cms.manage.template.value.TplValueStrategy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

import static cms.common.SystemConstant.DisplayType.DISPLAY_COLLECTION;
import static cms.common.SystemConstant.DisplayType.DISPLAY_ENTITYBEAN;

@Service("关注")
public class FollowStrategy implements TplValueStrategy {
    @Resource
    FollowTemplateManage followTemplateManage;//关注 -- 模板方法实现

    @Override
    public Object doOperation(Forum forum, Map submitParameter, Map runtimeParameter) {
        if(forum.getForumChildType().equals("关注用户")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = followTemplateManage.addFollowCollection(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("关注总数")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Long value = followTemplateManage.followCountEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("粉丝总数")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Long value = followTemplateManage.followerCountEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("是否已经关注该用户")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Boolean value = followTemplateManage.followingEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }
        return null;
    }
}
